import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import routesList from './routes'
import { checkHavePathInRoutes } from '@/utils/tips'

const routes: Array<RouteRecordRaw> = routesList

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL || '/'),
  routes
})

router.beforeEach((to, from, next) => {
  if (checkHavePathInRoutes(to.path, routes)) {
    next()
  } else {
    router.push({
      path: "/pages/404"
    })
  }
})

export default router
